package com.foreknow.oop;

import java.util.Arrays;

/**
 * 对象分组：数组中可以存对象
 */
public class ObjectArray {

    public void getAllMessage(Student[] array){
        for(int i = 0;i<array.length;i++){
            Student s=array[i];
            System.out.println(s.getName()+s.getAge());
        }
        for(Student ss:array)
            System.out.println(ss.getName()+ss.getAge());
    }
    public Student[] getAll(){
        Student[] array = new Student[2];
        //2.创建两个学生对象
        Student s1 = new Student();
        s1.setName("tom");
        s1.setAge(20);
        Student s2 = new Student();
        s2.setName("fender");
        s2.setAge(30);
        //3.将对象保存到数组中
        array[0] =s1;
        array[1] =s2;
        return array;
    }

    public static void main(String[] args) {
        //创建ObjectArray类的对象
        ObjectArray objectArray = new ObjectArray();
        Student[] sss=objectArray.getAll();
        for(Student array:sss){
            System.out.println(array.getName()+" "+array.getAge());
        }
        //1.创建一个Student类型的数组容器
 /*       Student[] array = new Student[2];
        //2.创建两个学生对象
        Student s1 = new Student();
        s1.setName("tom");
        s1.setAge(20);
        Student s2 = new Student();
        s2.setName("fender");
        s2.setAge(30);
        //3.将对象保存到数组中
        array[0] =s1;
        array[1] =s2;*/
       // objectArray.getAllMessage(array);
        //4.遍历数组获取到数组中的Student对象信息
/*        for(int i = 0;i<array.length;i++){
            Student s=array[i];
            System.out.println(s.getName()+s.getAge());
        }
        for(Student ss:array)
            System.out.println(ss.getName()+ss.getAge());*/
    }
}
